package com.kalua.list.domainmodel;

import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonIgnore;

public abstract class BaseIdentifier implements Identifier {
	
	private static final long serialVersionUID = -6154437374183758776L;

	@Override
	public int hashCode() { return Arrays.hashCode(getConstituents()); }
	
	@Override
	public boolean equals(Object other) {
		boolean result = false;		
		if (this == other)
			result = true;
		else if (other!=null && getClass().isInstance(other)) {
			BaseIdentifier candidate = (BaseIdentifier)other;  
			Object[] fields = getConstituents();
			Object[] otherFields = candidate.getConstituents();
			result = Arrays.equals(fields, otherFields);
		}		
		return result;
	}
	
	@Override
	public String toString() { return Arrays.toString(getConstituents()); }
	
	@JsonIgnore
	protected abstract Object[] getConstituents();
}